import wget,tempfile,os

wordFile = open("/home/guoxl/project/word.txt","r+")

def getWord(word):
    dir = "/home/guoxl/project/wordUs/"
    url = "http://dict.youdao.com/dictvoice?type=2&audio=" + word
    wget.download(url,out=os.path.join(dir,word+".mp3"))
    
exceptCnt = 0

for i in range(4524):

    LineBuffer = wordFile.readline()
    spaceLocation = LineBuffer.find(" ")
    strEn = LineBuffer[0:spaceLocation]

    if(os.path.isfile("/home/guoxl/project/wordUs/"+strEn+".mp3")):
#        exceptCnt = exceptCnt + 1
#        print("same: ",i+1-exceptCnt," "+strEn)
        continue
    else:
        print(strEn)

    try:
        getWord(strEn)
    except:
        exceptCnt = exceptCnt + 1
        print("error: ",i+1-exceptCnt," "+strEn)
    

wordFile.close()

